﻿using System;
using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Images;
using Silvermoon.Windows;
using Silvermoon.OpenGL;
using System.Drawing;
using Silvermoon.UI;

namespace Testing.Pages
{
    public class TextBox2Page : DemoWindowBase
    {
        #region text

        //private static readonly  string info = "Silvermoon requires hardware support for open gl and expects the libGLES_CM.dll to be available. However, in the source code is a software rendering replacement available, but this is really not recommended, unless you want to deal with 0.3fps instead of 25fps!";
        private static readonly string info = "Hello world";

        private static readonly string info2 = "Shape\nShapes are primitive classes which are used by controls to render its appearance. Generally spoken, a shape is a rectangle with an image. The image can be a rectangle (RectangleShape) or it can be a Circle (RoundShape) or any other image. A shape can even contain other shapes (MultiShape) to build complex images. But more about shapes later… \n\nControl\n" +
                            "Controls are the heart of Silvermoon. Controls have properties that describe the current characteristics and appearance of a control. For instance a button control has a IsPressed property, or almost every Control has a Color property. " +
                            "Controls use shapes to render their appearance. Therefore every control has a protected Shapes class which is a linked list of shapes (I prefer linked lists over lists, as they are about 20% faster for enumeration and consume only the storage they required). " +
                            "A Control can also host one (Decorator) or more (ContainerControl) controls. For instance a ListBox contains Items. " +
                            "There are controls which don’t have any appearance and are supposed to be used as container only, like Panel, and some have, like Button.  " +
                            " Visual controls (or ChromeControl) have a Background and a Chrome property which is of type shape. The background is the shape which is rendered as first of all other shapes and child controls. Chrome is the opposite and it is rendered after all other shapes and child controls. For instance, the picker makes use of the chrome to render a lens. " +
                            " Some controls have additional shapes, and you can always change the default shape directly by changing the property to another shape. ";
        #endregion

        private TextBox textBox;

        public TextBox2Page()
            : base()
        {
            InitializePage();
        }

        private void InitializePage()
        {
            Color = PhoneColors.MediumDark;
            ScrollPanel panel = new ScrollPanel { Margin = Margin.Zero };
            int w = Math.Max(ScrollViewer.ScrollbarWidth + 2, 20);
            textBox = new TextBox { Margin = new Margin(w, 10, w, 10), AutoHeight = true, Font = FontPool.TextBoxFont, AcceptReturn = true, Text = info, CharSpace = 1 };
            panel.Controls.Add(textBox);
            Controls.Add(panel);

            toolbar.Buttons.Add(new ToolbarButton(SysImages.Add, OnSetText));
            toolbar.Buttons.Add(new ToolbarButton(SysImages.Cancel, OnClearText));
            toolbar.Buttons.Add(new ToolbarButton(SysImages.Check, OnChangeAcceptReturn));
        }

        private void OnClearText(object sender, TapEventArgs e)
        {
            textBox.Text = "";
            textBox.Focus();
            this.IsKeyboardVisible = true;
        }

        private void OnSetText(object sender, TapEventArgs e)
        {
            textBox.Text = info2;
        }

        private void OnChangeAcceptReturn(object sender, TapEventArgs e)
        {
            textBox.AcceptReturn ^= true;
        }


        protected override void OnShown()
        {
            base.OnShown();
            Screen.Progress();
            //textBox.Highlight(4);
            //textBox.Highlight(5);
            //textBox.Highlight(6);
            //textBox.Highlight(10);

            //for (int i = 40; i < 50; i++) textBox.Highlight(i);

            //for (int i = 90; i < 210; i++) textBox.Highlight(i);
        }
    }
}
